package org.wangblue.index;

//导入这个包就可以正常运行了
import org.elasticsearch.client.indices.CreateIndexRequest;

import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.indices.CreateIndexResponse;
import org.wangblue.common.Client;

import java.io.IOException;

/**
 * @Description: ES中创建索引
 * @Author: WangBlue
 * @Create: 2024-10-22 15:08
 * @Version: 1.0
 **/

public class CreateIndex {
    public static void main(String[] args) throws IOException {
        // 1. 创建ES客户端
        RestHighLevelClient client = Client.getClient();

        // 2. 创建索引
        CreateIndexRequest request = new CreateIndexRequest("user4");

        // 3. 执行创建索引请求

        CreateIndexResponse response = client.indices().create(request, RequestOptions.DEFAULT);
        boolean acknowledged = response.isAcknowledged();

        // 4. 响应状态
        System.out.println("操作状态 = " + acknowledged);

        client.close();
    }
}
